﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    .form .formValue input.form-control {
        height: 34px;
        line-height: 34px;
    }

    .form-control {
        padding: 0px;
        height: 28px;
        line-height: 28px;
    }
</style>
<script>
    var dictionaryData;
    var workFlowDetailId = $.request("keyValue");
    var workFlowId = $.request("workFlowId");
    var mark = $.request("mark");

    $(function () {
        initData();
    });

    //初始化字典数据
    function initDictionryData() {
        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetDictionaryItemsJson",
            dataType: "json",
            async: false,
            success: function (data) {
                dictionaryData = data;
            }
        });
    }

    //初始化控件
    function initControl() {
        if (mark == 'detail') {
            $('.form-control').prop('disabled', true);
        }

        var $multipleSelectControls = $("#F_OpreationUserId, #F_OpreationType, #F_MessageSend, #F_CcUserId,#F_ConunTerisnUserId");

        $multipleSelectControls.bindSelect({
            placeholder: "请选择相关内容",
            multiple: true
        });

        var F_OperationPersonType = dictionaryData.F_OperationPersonType;
        for (var i = 0; i < F_OperationPersonType.length; i++) {
            $("#F_OperationPersonType").append("<option value='" + F_OperationPersonType[i].F_ItemCode + "'>" + F_OperationPersonType[i].F_ItemName + "</option>");
        }

        var F_CcOperationPType = dictionaryData.F_OperationPersonType;
        for (var i = 0; i < F_CcOperationPType.length; i++) {
            $("#F_CcOperationPType").append("<option value='" + F_CcOperationPType[i].F_ItemCode + "'>" + F_CcOperationPType[i].F_ItemName + "</option>");
        }

        var F_CounTersignType = dictionaryData.F_OperationPersonType;
        for (var i = 0; i < F_CounTersignType.length; i++) {
            $("#F_CounTersignType").append("<option value='" + F_CounTersignType[i].F_ItemCode + "'>" + F_CounTersignType[i].F_ItemName + "</option>");
        }

        var messageSends = dictionaryData.F_MessageSend;
        for (var i = 0; i < messageSends.length; i++) {
            $("#F_MessageSend").append("<option value='" + messageSends[i].F_ItemCode + "'>" + messageSends[i].F_ItemName + "</option>");
        }

        var opreationStrategies = dictionaryData.F_OpreationStrategy;
        for (var i = 0; i < opreationStrategies.length; i++) {
            $("#F_OpreationStrategy").append("<option value='" + opreationStrategies[i].F_ItemCode + "'>" + opreationStrategies[i].F_ItemName + "</option>");
        }

        var opreationTypes = dictionaryData.F_OpreationType;
        for (var i = 0; i < opreationTypes.length; i++) {
            $("#F_OpreationType").append("<option value='" + opreationTypes[i].F_ItemCode + "'>" + opreationTypes[i].F_ItemName + "</option>");
        }

        var returnStrategies = dictionaryData.F_ReturnStrategy;
        for (var i = 0; i < returnStrategies.length; i++) {
            $("#F_ReturnStrategy").append("<option value='" + returnStrategies[i].F_ItemCode + "'>" + returnStrategies[i].F_ItemName + "</option>");
        }

        var returnTypes = dictionaryData.F_ReturnType;
        for (var i = 0; i < returnTypes.length; i++) {
            $("#F_ReturnType").append("<option value='" + returnTypes[i].F_ItemCode + "'>" + returnTypes[i].F_ItemName + "</option>");
        }

        var timeOutOpreations = dictionaryData.F_TimeOutOpreation;
        for (var i = 0; i < timeOutOpreations.length; i++) {
            $("#F_TimeOutOpreation").append("<option value='" + timeOutOpreations[i].F_ItemCode + "'>" + timeOutOpreations[i].F_ItemName + "</option>");
        }

        var timeOutTips = dictionaryData.F_TimeOutTip;
        for (var i = 0; i < timeOutOpreations.length; i++) {
            $("#F_TimeOutTip").append("<option value='" + timeOutTips[i].F_ItemCode + "'>" + timeOutTips[i].F_ItemName + "</option>");
        }

        var users = dictionaryData.F_Users;
        for (var i = 0; i < users.length; i++) {
            $("#F_CcUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
            $("#F_OpreationUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
            $("#F_ConunTerisnUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
        }

        var persontype = dictionaryData.F_PersonType;
        for (var i = 0; i < persontype.length; i++) {
            $('#F_OperationPersonType').append("<option value='" + persontype[i].F_ItemCode + "'>" + persontype[i].F_ItemName + "</option>");
            $('#F_CcOperationPType').append("<option value='" + persontype[i].F_ItemCode + "'>" + persontype[i].F_ItemName + "</option>");
            $('#F_CounTersignType').append("<option value='" + persontype[i].F_ItemCode + "'>" + persontype[i].F_ItemName + "</option>");
        }
    }



    //初始化数据
    function initData() {
        initDictionryData();
        initControl();

        if (mark == 'add') {
            return;
        }

        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetWorkFlowDetailJson?keyValue=" + workFlowDetailId,
            dataType: "json",
            async: false,
            success: function (data) {
                if (data != null) {
                    if (data["F_MessageSend"] != null) {
                        $("#F_MessageSend").val(data["F_MessageSend"].split(',')).trigger('change');
                    }

                    if (data["F_OperationPersonType"] != null) {
                        $("#F_OperationPersonType").val(data["F_OperationPersonType"].split(',')).trigger('change');
                    }

                    if (data["F_OpreationUserId"] != null) {
                        $("#F_OpreationUserId").val(data["F_OpreationUserId"].split(',')).trigger('change');
                    }

                    if (data["F_CcOperationPType"] != null) {
                        $("#F_CcOperationPType").val(data["F_CcOperationPType"].split(',')).trigger('change');
                    }

                    if (data["F_OpreationType"] != null) {
                        $("#F_OpreationType").val(data["F_OpreationType"].split(',')).trigger('change');
                    }

                    if (data["F_CounTersignType"] != null) {
                        $("#F_CounTersignType").val(data["F_CounTersignType"].split(',')).trigger('change');
                    }

                    if (data["F_CcUserId"] != null) {
                        $("#F_CcUserId").val(data["F_CcUserId"].split(',')).trigger('change');
                    }

                    if (data["F_ConunTerisnUserId"] != null) {
                        $('#F_ConunTerisnUserId').val(data["F_ConunTerisnUserId"].split(',')).trigger('change');
                    }

                    $("#F_Id").val(data["F_Id"]);
                    $("#F_WorkFlowId").val(data["F_WorkFlowId"]);
                    $("#F_StepName").val(data["F_StepName"]);

                    $("#F_TimeOutTip").val(data["F_TimeOutTip"]);
                    $("#F_IsFishTime").val(data["F_IsFishTime"]);
                    $("#F_WorkHours").val(data["F_WorkHours"]);
                    //ChangeCityData();
                    $("#F_TimeOutOpreation").val(data["F_TimeOutOpreation"]);
                    $("#F_OpreationStrategy").val(data["F_OpreationStrategy"]);
                    $("#F_ReturnStrategy").val(data["F_ReturnStrategy"]);
                    $("#F_ReturnType").val(data["F_ReturnType"]);
                    $("#F_WorkFlowNo").val(data["F_WorkFlowNo"]);
                    $("#F_CountersignNum").val(data["F_CountersignNum"]);

                    $('#F_ApprovalNo').val(data["F_ApprovalNo"]);

                    $('#F_IsCountersign').prop("checked", data["F_IsCountersign"]);
                    if (data["F_IsCountersign"] == 1) {
                        $("#F_CountersignNum").removeAttr("disabled");
                    }
                    //$('#F_OperationPersonType').val(data["F_OperationPersonType"]);
                    //$('#F_CcOperationPType').val(data["F_CcOperationPType"]);
                    //$('#F_CounTersignType').val(data["F_CounTersignType"]);

                }
            }
        });
    }

    //获取多选框选中字符串值
    function getMultipleSelectDataString(element) {
        var data = element.select2("data");
        var dataString = "";

        for (var i = 0; i < data.length; i++) {
            if (i == data.length - 1) {
                dataString += data[i].id;
            } else {
                dataString += data[i].id + ",";
            }
        }

        return dataString;
    }

    //提交表单
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }

        var ccUserIdsString = getMultipleSelectDataString($("#F_CcUserId"));
        var opreationUserIdsString = getMultipleSelectDataString($("#F_OpreationUserId"));
        var messageSendsString = getMultipleSelectDataString($("#F_MessageSend"));
        var opreationTypesString = getMultipleSelectDataString($("#F_OpreationType"));

        var conunterisnusersString = getMultipleSelectDataString($('#F_ConunTerisnUserId'));
        if (!conunterisnusersString)
            conunterisnusersString = "   ";
        $.submitForm({
            url: "/WorkFlowSetting/FlowManage/SaveWorkFlowDetail?keyValue=" + workFlowDetailId,
            param: {
                'F_Id': workFlowDetailId,
                'F_WorkFlowId': workFlowId,
                'F_StepName': $('#F_StepName').val(),
                'F_WorkFlowNo': $('#F_WorkFlowNo').val(),
                'F_TimeOutTip': $('#F_TimeOutTip').val(),
                'F_IsFishTime': $('#F_IsFishTime').val(),
                'F_WorkHours': $('#F_WorkHours').val(),
                'F_TimeOutOpreation': $('#F_TimeOutOpreation').val(),
                'F_OpreationType': opreationTypesString,
                'F_OpreationUserId': opreationUserIdsString,
                'F_OpreationStrategy': $('#F_OpreationStrategy').val(),
                'F_ReturnStrategy': $('#F_ReturnStrategy').val(),
                'F_ReturnType': $('#F_ReturnType').val(),
                'F_MessageSend': messageSendsString,
                'F_CcUserId': ccUserIdsString,
                'F_ConunTerisnUserId': conunterisnusersString,
                'F_IsCountersign': $('#F_IsCountersign')[0].checked ? 1 : 0,
                'F_OperationPersonType': $('#F_OperationPersonType').val(),
                'F_CcOperationPType': $('#F_CcOperationPType').val(),
                'F_CounTersignType': $('#F_CounTersignType').val(),
                'F_ApprovalNo': $('#F_ApprovalNo').val(),
                'F_CountersignNum': $('#F_CountersignNum').val()
            },
            success: function (result) {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });

        return true;
    }

    function OperationPersonTypeChange() {
        var F_OperationPersonType = $("#F_OperationPersonType").val();
        $("#F_OpreationUserId").empty();
        if (F_OperationPersonType == "1") {
            var users = dictionaryData.F_Users;
            for (var i = 0; i < users.length; i++) {
                $("#F_OpreationUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
            }
        } else {
            var F_Roles = dictionaryData.F_Roles;
            for (var i = 0; i < F_Roles.length; i++) {
                $("#F_OpreationUserId").append("<option value='" + F_Roles[i].F_Id + "'>" + F_Roles[i].F_FullName + "</option>");
            }
        }
    }

    function CcOperationPTypeChange() {
        var F_CcOperationPType = $("#F_CcOperationPType").val();
        $("#F_CcUserId").empty();
        if (F_CcOperationPType == "1") {
            var users = dictionaryData.F_Users;
            for (var i = 0; i < users.length; i++) {
                $("#F_CcUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
            }
        } else {
            var F_Roles = dictionaryData.F_Roles;
            for (var i = 0; i < F_Roles.length; i++) {
                $("#F_CcUserId").append("<option value='" + F_Roles[i].F_Id + "'>" + F_Roles[i].F_FullName + "</option>");
            }
        }
    }

    function CounTersignTypeChange() {
        var F_CounTersignType = $("#F_CounTersignType").val();
        $("#F_ConunTerisnUserId").empty();
        if (F_CounTersignType == "1") {
            var users = dictionaryData.F_Users;
            for (var i = 0; i < users.length; i++) {
                $("#F_ConunTerisnUserId").append("<option value='" + users[i].F_Id + "'>" + users[i].F_Account + "</option>");
            }
        } else {
            var F_Roles = dictionaryData.F_Roles;
            for (var i = 0; i < F_Roles.length; i++) {
                $("#F_ConunTerisnUserId").append("<option value='" + F_Roles[i].F_Id + "'>" + F_Roles[i].F_FullName + "</option>");
            }
        }
    }
</script>

<form id="form1">
    <div style="padding-left:20px">
        <table class="form">
            <tr>
                <td class="formValue" colspan="7"></td>
            </tr>
            <tr>
                <td class="formTitle">流程顺序</td>
                <td class="formValue" colspan="1">
                    <input type="number" id="F_WorkFlowNo" name="F_WorkFlowNo" class="form-control required" />
                </td>
                <td class="formTitle">步骤名称</td>
                <td class="formValue" colspan="1">
                    <input id="F_StepName" name="F_StepName" type="text" class="form-control required" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">超期提示</td>
                <td class="formValue" colspan="1">
                    <select id="F_TimeOutTip" name="F_TimeOutTip" class="form-control" onchange="">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">工时（小时）</td>
                <td class="formValue" colspan="1">
                    <input type="text" id="F_WorkHours" name="F_WorkHours" class="form-control " placeholder="" />
                </td>
                <td class="formTitle">超时处理</td>
                <td class="formValue" colspan="1">
                    <select id="F_TimeOutOpreation" name="F_TimeOutOpreation" class="form-control " onchange="">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td class="formTitle">处理策略</td>
                <td class="formValue" colspan="1">
                    <select id="F_OpreationStrategy" name="F_OpreationStrategy" class="form-control required" onchange="">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">退回策略</td>
                <td class="formValue" colspan="1">
                    <select id="F_ReturnStrategy" name="F_ReturnStrategy" class="form-control required">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">退回类型</td>
                <td class="formValue" colspan="1">
                    <select id="F_ReturnType" name="F_ReturnType" class="form-control required">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>
            <tr>

                <td class="formTitle">处理方式</td>
                <td class="formValue" colspan="1">
                    <select id="F_OpreationType" name="F_OpreationType" class="form-control "></select>
                </td>
                <td class="formTitle">处理人类型</td>
                <td class="formValue" colspan="1">
                    <select id="F_OperationPersonType" name="F_OperationPersonType" class="form-control" onchange="OperationPersonTypeChange()">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">处理人</td>
                <td class="formValue" colspan="1">
                    <select id="F_OpreationUserId" name="F_OpreationUserId" class="form-control required"></select>
                </td>
            </tr>
            <tr>
                <td class="formTitle">审批顺序</td>
                <td class="formValue" colspan="1">
                    <select id="F_ApprovalNo" name="F_ApprovalNo" class="form-control required">
                        <option value="">==请选择==</option>
                        <option value="1">依次执行</option>
                        <option value="2">同时执行</option>
                    </select>
                </td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td class="formTitle">消息发送方式</td>
                <td class="formValue" colspan="1">
                    <select id="F_MessageSend" name="F_MessageSend" class="form-control required" onchange=""></select>
                </td>
                <td class="formTitle">抄送人类型</td>
                <td class="formValue" colspan="1">
                    <select id="F_CcOperationPType" name="F_CcOperationPType" class="form-control required" onchange="CcOperationPTypeChange()">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">抄送人</td>
                <td class="formValue" colspan="1">
                    <select id="F_CcUserId" name="F_CcUserId" class="form-control" onchange=""></select>
                </td>
            </tr>
            <tr>
                <td class="formTitle">是否会签</td>
                <td class="formValue" colspan="1">
                    <input id="F_IsCountersign" name="F_IsCountersign" type="checkbox"><label for="F_IsCountersign">是</label>

                </td>
                <td class="formTitle">会签人类型</td>
                <td class="formValue" colspan="1">
                    <select id="F_CounTersignType" name="F_CounTersignType" class="form-control" onchange="CounTersignTypeChange()">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">会签人</td>
                <td class="formValue" colspan="1">
                    <select id="F_ConunTerisnUserId" name="F_ConunTerisnUserId" class="form-control" onchange=""></select>
                </td>
            </tr>
            <tr>
                <td class="formTitle">会签步骤</td>
                <td class="formValue" colspan="1">
                    <input type="number" disabled name="F_CountersignNum" id="F_CountersignNum" />
                </td>
            </tr>
        </table>
    </div>
</form>
